package com.zzh.structuredeployment

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityOptionsCompat
import androidx.fragment.app.Fragment
import com.zzh.bridge.BridgeIntent
import com.zzh.bridge.page.PageApp
import com.zzh.bridge.page.PageWeb
import com.zzh.bridge_annotation.RouteTag
import com.zzh.custom.dialog.CommonDialog
import com.zzh.log.LogU
import com.zzh.log_annotation.AddLog
import com.zzh.structuredeployment.activity.FourActivity
import com.zzh.structuredeployment.bridge.BridgeApp
import com.zzh.custom.dialog.CommentsDialog
import com.zzh.tools.hook.HookClickListener
import com.zzh.tools.utils.ToolBundle
import com.zzh.tools.utils.ToolLog
import com.zzh.tools.utils.ToolMap
import com.zzh.web.bridge.BridgeWeb
import kotlinx.android.synthetic.main.activity_main.*

@RouteTag(BridgeApp.MAIN)
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        skipAgainst.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME,PageApp.AGAINST,this@MainActivity)
        }
        skipRefresh.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.REFRESH, this@MainActivity)
        }
        skipChaosList.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.CHAOS_LIST, this@MainActivity)
        }
        skipLoading.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.LOADING, this@MainActivity)
        }
        skipEr.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.SECOND, this@MainActivity)
        }

        room.setOnClickListener {
            onTest()
        }

        skipSelecttor.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.SELECTOR, this@MainActivity)
        }

        skipweb.setOnClickListener {
            BridgeIntent.start(PageWeb.MOUDLE_NAME, PageWeb.WEB, this@MainActivity)
        }

        skipThrid.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.THRID, this@MainActivity)
        }

        skipViewAnimtor.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.FOUR, this@MainActivity)
        }

        HookClickListener.hooksOnClickListener(window.decorView)
        skipDialog.setOnClickListener {
            showSelfDialog(count % 6)
            count++
        }

        skipPicture.setOnClickListener {
            var list = arrayListOf<Map<String, String>>()
            for (i in 1..4) {
                var map = HashMap<String, String>()
                map["drawId"] = R.mipmap.ic_launcher.toString()
                list.add(map)
            }
            val intent = Intent(
                this@MainActivity,
                FourActivity::class.java
            )
            intent.putExtra("data", list)
            intent.putExtra("position", 0)
            val optionsCompat =
                ActivityOptionsCompat.makeScaleUpAnimation(
                    it,
                    it.width / 2,
                    it.height / 2,
                    it.width,
                    it.height
                )
            startActivity(intent, optionsCompat.toBundle())
        }

        skipEdit.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.EDIT, this@MainActivity)
        }

        skipCompare.setOnClickListener {
            BridgeIntent.start(
                PageApp.MOUDLE_NAME, PageApp.COMPARE, this@MainActivity,
                ToolBundle.createBundle(
                    ToolBundle.PAGE_COMPARE,
                    ToolMap.createMap("one", 0, "two", 0, "three", 0, "four", 0, "five", 0)
                )
            )
        }

        skipNine.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.NINE, this@MainActivity)
        }

        skipRelease.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.RELEASE, this@MainActivity)
        }

        showComment.setOnClickListener {
            CommentsDialog.Builder()
                .setPromptTextStr("请输入。。。")
                .setTextStr("张志浩")
                .setOnSendClickListener { value ->
                    ToolLog.i("zzh", ">send>${value}>>>")
                }
                .create(this@MainActivity)
                .show("comments")
        }

        skipMenu.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.MENU, this@MainActivity)
        }

        skipSearch.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.SEARCH, this@MainActivity)
        }

        skipEleven.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.ELEVEN, this@MainActivity)
        }

        skipTwelve.setOnClickListener {
            BridgeIntent.start(PageApp.MOUDLE_NAME, PageApp.TWELVE, this@MainActivity)
        }

        HookClickListener.hooksOnClickListener(window.decorView)
    }


    @AddLog
    fun onTest() {
        flowTextView.setTexts(
            "哈哈 哈哈哈 哈哈哈 啊啊哈哈 急急急 酷酷酷 哦哦哦 啦啦啦 买买买 哈哈 哈哈哈 哈哈哈 啊啊哈哈 急急急 酷酷酷 哦哦哦 啦啦啦 买买买 哈哈 哈哈哈 哈哈哈 啊啊哈哈 急急急 酷酷酷 哦哦哦 啦啦啦 买买买 哈哈 哈哈哈 哈哈哈 啊啊哈哈 急急急 酷酷酷 哦哦哦 啦啦啦 买买买",
            " "
        )
        var obg: Any? = BridgeIntent.getBridgeObject(BridgeWeb.MOUDLE_NAME, BridgeWeb.WEB_TEST)
        var fragment: Fragment? =
            BridgeIntent.getFragment(BridgeWeb.MOUDLE_NAME, BridgeWeb.WEB_TEST)
        obg?.let {
            Log.i("zhangzhihao", "${it.javaClass.name} 不是空1")
        }

        fragment?.let {
            Log.i("zhangzhihao", "${it.javaClass.name} 不是空2")
        }

        LogU().test()
    }

    var count = 0
    private fun showSelfDialog(index: Int) {
        when (index) {
            0 -> {
                CommonDialog.Builder()
                    .setTitle("你看这里有个title")
                    .setShowContent(false)
                    .create(this@MainActivity)
                    .show("test")
            }
            1 -> {
                CommonDialog.Builder()
                    .setContent("我是展示的内容${index}")
                    .setShowTitle(false)
                    .create(this@MainActivity)
                    .show("test")
            }
            2 -> {
                CommonDialog.Builder()
                    .setContent("我是展示的内容${index}")
                    .setTitle("你看这里有个title")
                    .create(this@MainActivity)
                    .show("test")
            }
            3 -> {
                CommonDialog.Builder()
                    .setShowList(true)
                    .setContents(testBeans())
                    .setShowRight(false)
                    .setShowLeft(false)
                    .create(this@MainActivity)
                    .show("test")
            }
            4 -> {
                CommonDialog.Builder()
                    .setShowRight(false)
                    .setShowLeft(false)
                    .setShowContent(false)
                    .setTitle("你看这里有个title")
                    .create(this@MainActivity)
                    .show("test")
            }
            5 -> {
                CommonDialog.Builder()
                    .setShowRight(false)
                    .setShowLeft(false)
                    .setShowTitle(false)
                    .setContent("我是展示的内容${index}")
                    .create(this@MainActivity)
                    .show("test")
            }
        }
    }

    private fun testBeans(): List<CommonDialog.ItemBean> {
        var list = arrayListOf<CommonDialog.ItemBean>()
        for (i in 1..13) {
            list.add(CommonDialog.ItemBean {
                ">>>${i}"
            })
        }
        return list
    }


}